import Vuex from "vuex";
import Vue from "vue";
import * as types from "./types";

Vue.use(Vuex);
export default new Vuex.Store({
  state: {
    username: null,
    token: null,
    title: "",
  },
  mutations: {
    [types.LOGIN]: (state, data) => {
      localStorage.token = data[0];
      localStorage.username = data[1];
      state.token = data[0];
      state.username = data[1];
    },
    [types.LOGOUT]: (state) => {
      localStorage.removeItem("token");
      localStorage.removeItem("username");
      state.token = null;
      state.username = null;
    },
    [types.TITLE]: (state, data) => {
      state.title = data;
    },
  },
});
